//
//  CardHeaderView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/12.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "CardHeaderView.h"

@implementation CardHeaderView{
    GLGWLabel * cardNumLabel;
    GLGWButton * delegateBut;
}

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        cardNumLabel = [[GLGWLabel alloc] initWithFont:BOLDSYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self];
        [cardNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(15));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        }];
        cardNumLabel.text = @"第一条";
        //按钮
        delegateBut = [[GLGWButton alloc] initInSuperView:self];
        delegateBut.hidden = YES;
//        delegateBut.backgroundColor = kRandomColor;
        delegateBut.image_Name = @"icon_quxiao";
        [delegateBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(20)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        [delegateBut addTarget:self action:@selector(deletNowRow) forControlEvents:UIControlEventTouchUpInside];
        //
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.bottom.equalTo(self).offset(0);
            make.height.equalTo(@(1));
        }];
    }
    return self;
}

-(void)indexAll:(NSInteger)allNum nowIndex:(NSInteger)nowNum{
    int num = (int)nowNum + 1;
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
    NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:num]];
    cardNumLabel.text = [NSString stringWithFormat:@"第%@条",string];
    //
    if (allNum > 1) {
        delegateBut.hidden = NO;
    }else{
        delegateBut.hidden = YES;
    }
}

-(void)deletNowRow{
    if (self.Block_Delete) {
        self.Block_Delete();
    }
}
@end
